<%@ page import="com.wuming.caiwu.security.SecurityHander" %><%--
  Created by IntelliJ IDEA.
  User: hanfei
  Date: 18/6/26
  Time: 下午5:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>订单信息管理</title>
    <link rel="stylesheet" href="${allServerPath}static/layui/layui/css/layui.css">
    <link rel="stylesheet" href="${allServerPath}static/layui/css/formSelects-v4.css">
    <style>
        .query-condition {
            margin-top: 15px;
        }
    </style>
</head>
<body style="background-color: #f0f2f5;">
<div style="padding: 15px;margin: 15px;background-color: #fff;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>订单信息管理</legend>
    </fieldset>
    <form id="queryForm" class="layui-form" action="">
        <div class="" style="margin-top: 15px;">
            <div class="layui-row query-condition">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">订单编号</label>

                        <div class="layui-input-inline">
                            <input type="text" id="orderSn" name="orderSn" placeholder="请输入订单编号"
                                   lay-verify="orderSn"
                                   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">订单状态</label>

                        <div class="layui-input-inline">
                            <select id="orderStatus" name="orderStatus"
                                    lay-filter="orderStatus">
                                <option value=""></option>
                                <option value="12">未支付</option>
                                <option value="1">付款中</option>
                                <option value="2">已付款</option>
                                <option value="7">已完成</option>
                                <option value="14">已退款</option>
                                <%--<option value="15">已关闭</option>--%>
                                <option value="20">待取消</option>
                            </select>
                        </div>

                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">店铺名称</label>

                        <div class="layui-input-inline">
                            <select id="qsgStoreId" name="qsgStoreId" lay-filter="qsgStoreId">
                                <option value=""></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">创建时间</label>

                        <div class="layui-input-inline">
                            <input type="text" name="startDate" id="startDate" placeholder=""
                                   autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" name="endDate" id="endDate" placeholder=""
                                   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <input type="hidden" id="payType" value="${payType}"/>
    </form>

    <div class="layui-row query-condition" style="padding: 9px 15px;margin-bottom: 20px;">
        <button name="btnQuery" class="layui-btn layui-btn-normal" data-type="reload">查询搜索</button>
    </div>

    <table class="layui-hide" id="studentsInfo" lay-filter="demo" lay-data="{height: 'full-200'}">
    </table>
</div>


<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
</script>

<%--<script type="text/html" id="paypriceTpl">--%>
    <%--<span style="color: #F581B1;">{{d.payAmount}}</span>--%>
<%--</script>--%>


<script type="text/html" id="statusTpl">
    {{#  if(d.orderStatus == '12'){ }}
    <span>未支付</span>
    {{#  } else if(d.orderStatus == '1'){ }}
    <span>付款中</span>
    {{#  } else if(d.orderStatus == '2'){ }}
    <span>已付款</span>
    {{#  } else if(d.orderStatus == '7'){ }}
    <span>已完成</span>
    {{#  } else if(d.orderStatus == '14'){ }}
    <span>已退款</span>
    {{#  } else if(d.orderStatus == '15'){ }}
    <span>已关闭</span>
    {{#  } else if(d.orderStatus == '20'){ }}
    <span>待取消</span>
    {{#  } }}
</script>


<script type="text/html" id="qsgStoreTpl">
    {{#  if(d.qsgStore != null){ }}
    <span>{{ d.qsgStore.name }}</span>
    {{#  } else { }}
    <span></span>
    {{#  }  }}
</script>

<script src="${allServerPath}static/layui/layui/layui.js"></script>
<script>
    layui.config({
        base: '${allServerPath}static/layui/build/js/'
    }).extend({
        formSelects: 'formSelects-v4.min'
    }).use(['table', 'jquery', 'navbar', 'laydate', 'form', 'element', 'formSelects'], function () {
        var table = layui.table,
            $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate,
            formSelects = layui.formSelects,
            element = layui.element;

        $(document).ready(function(){
            $.ajax({
                type: 'get',
                url: '${allServerPath}web/store/listAll.htmls',
                dataType: 'JSON',
                success: function (obj) {
                    if (obj.success) {
                        $.each(obj.data, function (index, item) {
                            var s = "<option value='" + item.id + "'>" + item.name + "</option>";
                            $("#qsgStoreId").append(s);
                        })
                        form.render();
                    }
                }
            });
        });

        laydate.render({
            elem: '#startDate',
            type: 'date'
        });

        laydate.render({
            elem: '#endDate',
            type: 'date'
        });

        table.render({ //其它参数在此省略
            elem: '#studentsInfo'
//            , height: 500
            , url: '${allServerPath}web/order/list.htmls?t=' + Date.parse(new Date())
            , cols: [[ //表头
                {field: 'id', width: 80, title: '序号', fixed: 'left'}
                , {field: 'memberId', title: '会员ID', align: 'center', width: 120}
                , {field: 'memberName', title: '会员名', align: 'center', width: 200}
                , {field: 'orderStatus', title: '订单状态', align: 'center', width: 120, templet: '#statusTpl'}
                , {field: 'createDatetime', title: '创建时间', align: 'center', width: 260}
                , {field: 'price', title: '订单金额', align: 'center', width: 120}
                , {field: 'qsgStore', title: '门店名称', align: 'center', width: 120,templet: '#qsgStoreTpl'}
                , {field: 'orderSn', title: '订单编号', align: 'center', width: 300}
                , {field: 'deviceId', title: '设备ID', align: 'center', width: 100}
                , {field: 'mealName', title: '套餐名称', align: 'center', width: 160}
                , {field: 'startTime', title: '开始时间', align: 'center', width: 180}
                , {field: 'endTime', title: '结束时间', align: 'center', width: 180}
                , {fixed: 'right', title: '操作', align: 'center', templet: '#barDemo',width: 180}
            ]],
            id: 'studentContent',
            where: {
                "payType": $("#payType").val()
            }, //如果无需传递额外参数，可不加该参数
            method: 'get', //如果无需自定义HTTP类型，可不加该参数
            page: true,
            limits: [10, 20, 30, 50, 100, 200],
            limit: 10,
            request: {
                pageName: 'pageIndex', //页码的参数名称，默认：page
                limitName: 'pageSize'
            }, //如果无需自定义请求参数，可不加该参数
            response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , statusCode: 200 //成功的状态码，默认：0
                , msgName: 'message' //状态信息的字段名称，默认：msg
                , countName: 'total' //数据总数的字段名称，默认：count
                , dataName: 'data' //数据列表的字段名称，默认：data
            }, //如果无需自定义数据响应名称，可不加该参数
            done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                console.log(res);

                //得到当前页码
                console.log(curr);

                //得到数据总量
                console.log(count);
            },
            text: {
                none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }
        });


        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                            url: '${allServerPath}web/order/delete/' + data.id + ".htmls",
                            method: 'get',
                            dataType: 'json',
                            success: function (result) {
                                if (result.success) {
                                    obj.del();
                                    layer.close(index);
                                }
                            },
                            error: function () {
                                layer.msg('删除失败,请稍后重试.');
                            }
                        }
                    );
                });
            }
        });

        $('button[name="btnQuery"]').on('click', function () {
            var orderStatus = $("#orderStatus").val();
            var startDate = $("#startDate").val();
            var endDate = $("#endDate").val();
            var orderSn = $("#orderSn").val();
            var storeId = $("#qsgStoreId").val();
            var payType = $("#payType").val();

            table.reload('studentContent', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    "storeId": storeId,
                    "orderStatus": orderStatus,
                    "orderSn": orderSn,
                    "payType": payType,
                    "startDate": startDate,
                    "endDate": endDate
                }
            });
        })
    })

</script>
</body>
</html>
